import random

num = random.randint(1,100)

# 我的版本：
# guess_num = int(input("请输入您猜的数(1~100)："))
# i = 1
#
# while guess_num != num:
#     if guess_num >num:
#         guess_num = int(input(f"猜大了，已经猜了{i}次，再猜一次(1~100)："))
#         i += 1
#     else:
#         guess_num = int(input(f"猜小了，已经猜了{i}次，再猜一次(1~100)："))
#         i += 1
# print(f"猜对了，是{guess_num}！您共猜测了{i}次")

# 网课版本：
# count = 0
# flag = True
# while flag:
#    guess_num = int(input("请输入您猜的数(1~100)："))
#    count+=1
#    if guess_num == num:
#        print("猜中了")
#        # 设置False就是终止循环的条件
#        flag = False
#    else:
#     if guess_num >num:
#         print("猜大了")
#     else:
#         print("猜小了")
#
# print(f"您共猜测了{count}次")

# 我的版本2：
guess_num = int(input("请输入您猜的数(1~100)："))
i = 1
while guess_num != num:
    if guess_num >num:
        print(f"猜大了，已经猜了{i}次")

    else:
        print(f"猜小了，已经猜了{i}次")
    guess_num = int(input("请再次输入您猜的数(1~100)："))
    i += 1

print(f"猜对了，是{guess_num}！您共猜测了{i}次")